<?php
	$this->pageTitle = $data->full_name;
?>
<div class="c_body">
	<?php if($data->id == Yii::app()->user->id || $data->view_info == 1 || ($data->view_info == 2 && isset($data->isFriend) && $data->isFriend->status)) : ?>
		<div class="l">
			<div class="u_block1">
				<div class="u_photo">
					<?php if($data->avatar){ ?>
						<a href="<?php echo Yii::app()->createUrl('albums/photo', array('id'=>$data->avatar));?>" class="photoBg">
							<?php if($data->avatar_info){ ?>
								<?php echo $this->material_image(0, $data->avatar_info->name, '200', 'photos/'. $data->id . '/' . 0); ?>
							<?php }else{ ?>
								<?php echo $this->material_image(0, 'noimage.gif', '200', ''); ?>
							<?php } ?>	
						</a>
					<?php }else{ ?>
						<?php echo $this->material_image(0, 'noimage.gif', '200', ''); ?>
					<?php } ?>
				</div>
								
				<div class="u_online <?php echo ($data->last_visit > date("Y-m-d H:i:s", time() - 15*60)) ? 'active' : ''; ?>">
					<div class="c">
						<div class="cc">
							<div class="u_online_icon"></div>
							<?php if($data->last_visit > date("Y-m-d H:i:s", time() - 15*60)){ ?>
								<div class="u_online_text">Сейчас на сайте</div>
							<?php }else{ ?>
								<div class="u_online_text">Нет на сайте</div>
							<?php } ?>
						</div>
					</div>
				</div>
				<?php if($_GET['id'] == Yii::app()->user->id){ ?>
					<a href="<?php echo Yii::app()->createUrl('news/index', array('id'=>Yii::app()->user->id));?>" class="u_link ajaxLink"><em>Мои Новости</em></a>
					<a href="<?php echo Yii::app()->createUrl('profile/settingsPersonal',array('id'=>$data->id));?>" class="u_link ajaxLink"><em>Редактировать страницу</em></a>
					<a href="<?php echo Yii::app()->createUrl('profile/uploadAvatar',array('id'=>$data->id));?>" class="u_link uploadAvatar"><em>Изменить фото</em></a>
					<div class="u_rating">
						<div class="u_rating_num"><?php echo $percent ?>%</div>
						<div class="u_rating_bar"><div class="u_rating_bar_inside" style="width:<?php echo $percent ?>%"></div></div>
					</div>			
				<?php }else{ ?>
					<?php if($data->get_message == 1 || ($data->get_message == 2 && isset($data->checkFriend) && $data->checkFriend->status)){ ?>
						<a href="<?php echo Yii::app()->createUrl('messages/getdialog', array('companion' => $_GET['id'], 'profile'=>Yii::app()->user->id));?>" class="u_link ajaxLink"><em>Написать сообщение</em></a>
					<?php } ?>
					<?php if(!isset($data->isBan)){ ?>
						<a href="<?php echo Yii::app()->createUrl('profile/addBlackList', array('blacklist' => $_GET['id'], 'profile'=>Yii::app()->user->id));?>" class="u_link removeLink" ><em>Заблокировать</em></a>
					<?php } else { ?>
						<a href="<?php echo Yii::app()->createUrl('profile/deleteBlackList', array('blacklist' => $_GET['id'], 'profile'=>Yii::app()->user->id));?>" class="u_link removeLink" ><em>Разблокировать</em></a>
					<?php } ?>
					<?php if($data->isFriend){ ?>
						<div class="u_rating">
							<?php if($data->isFriend->status){ ?>
								<div class="u_rating_num"><?php echo CHtml::encode($data->full_name); ?> в списке Ваших друзей</div>
							<?php }else{ ?>
								<div class="u_rating_num"><?php echo CHtml::encode($data->full_name); ?> еще не <?php if($data->sex == 'W'){ echo 'подтвердила'; }else{ echo 'подтвердил'; }?> запрос на дружбу</div>
							<?php } ?>
						</div>
					<?php }else{ ?>
						<a href="<?php echo Yii::app()->createUrl('profile/addfriend', array('friend_id' => $_GET['id']));?>" class="u_link" id="add-friend"><em>Добавить в друзья</em></a>
					<?php } ?>
				<?php } ?>
			</div>
			<?php if($_GET['id'] == Yii::app()->user->id) {?>
				<div class="u_block2 ajaxLinks">
					<?php if($data->countAlbums==0) {?>
						<a href="<?php echo Yii::app()->createUrl('albums/index', array('profile'=>$_GET['id']));?>" class="u_add">Добавить фотографии (+15)</a>
					<?php } ?>
					<?php if(!$data->birthday){ ?>
						<a href="<?php echo Yii::app()->createUrl('profile/settingsPersonal', array('id'=>$_GET['id']));?>" class="u_add">Указать год рождения (+10)</a>
					<?php } ?>
					<?php if(!$data->teach){ ?>
						<a href="<?php echo Yii::app()->createUrl('profile/settingsPersonal', array('id'=>$_GET['id']));?>" class="u_add">Рассказать о школе (+10)</a>
					<?php } ?>
					<?php if(!$data->country_id || !$data->city || !$data->address || !$data->phone){ ?>
						<a href="<?php echo Yii::app()->createUrl('profile/settingsPersonal', array('id'=>$_GET['id']));?>" class="u_add">Заполнить контакты (+10)</a>
					<?php } ?>
					<?php if($data->countGroups==0) {?>
						<a href="<?php echo Yii::app()->createUrl('search/index', array('tab'=>'groups'));?>" class="u_add">Добавить сообщества (+10)</a>
					<?php } ?>
				</div>
			<?php } ?>
			
			<?php $this->renderPartial('_friends',array(
				'friends'=>$data->friends,
				'countFriends'=>$data->countFriends
			)); ?>
			
			<?php $this->renderPartial('_friends_online',array(
				'friends'=>$friends_online,
				'countFriends'=>$data->countFriends
			)); ?>

			<?php 
				if($data->id == Yii::app()->user->id || $data->view_photo == 1 || ($data->view_photo == 2 && isset($data->isFriend) && $data->isFriend->status)){
					$this->renderPartial('_albums',array(
						'countAlbums'=>$data->countAlbums,
						'albums'	 =>$data->albums
					)); 
				}
			?>
			
			<?php 
				if($data->id == Yii::app()->user->id || $data->view_video == 1 || ($data->view_video == 2 && isset($data->isFriend) && $data->isFriend->status)){
					$this->renderPartial('_videos',array(
						'countVideos'=>$data->countVideos,
						'videos'	 =>$data->videos
					)); 
				}
			?>		
		</div>
		<div class="r">
			<div class="user_head">
				<h1><?php echo CHtml::encode($data->full_name); ?></h1>
				<div class="user_status_block">
					<?php if(Yii::app()->user->id == $_GET['id']){ ?>
						<div class="new_status_form old <?php if(!$data->status){ echo 'hidden'; } ?>">
							<p>Статус:</p> <a href="" id="user_status" onclick="return false;"><?php echo CHtml::encode($data->status); ?></a>
						</div>		
						<div class="new_status_form <?php if($data->status){ echo 'hidden'; } ?>">
							<p>Статус:</p>
							<form action="<?php echo Yii::app()->createAbsoluteUrl('profile/updateStatus', array('id'=>$_GET['id'])); ?>" method="get" id="status_form">
								<div class="user_status_fld_block">
									<div class="user_status_btn" id="new_status_button"></div>
									<div class="user_status_fld_r">
										<div class="user_status_fld_l">
											<input type="text" name="status" class="user_status_fld" value="<?php echo $data->status; ?>" placeholder="напишите новый статус" />
										</div>
									</div>
								</div>	
							</form>
						</div>		
					<?php }else{ ?>
						<p id="user_status_text"><?php echo CHtml::encode($data->status); ?></p>
					<?php } ?>
				</div>
			</div>

			<div class="user_block">
				<div class="u_cat_head"><i>Личная</i> информация</div>
				<table class="user_info_table">
					<?php if($data->country_id){ ?>
						<tr>
							<td class="user_info_l">Страна:</td>
							<td class="user_info_r"><a href="<?php echo Yii::app()->createUrl('search/index', array('tab'=>'people', 'filter_country'=>$data->country_id));?>"><?php echo CHtml::encode($data->country->name); ?></a></td>
						</tr>
					<?php } ?>
					<?php if($data->city){ ?>
						<tr>
							<td class="user_info_l">Город:</td>
							<td class="user_info_r"><a href="<?php echo Yii::app()->createUrl('search/index', array('tab'=>'people', 'filter_city'=>$data->city));?>"><?php echo CHtml::encode($data->city); ?></a></td>
						</tr>
					<?php } ?>
					<?php if($data->birthday){ ?>
						<tr>
							<td class="user_info_l">Дата рождения:</td>
							<td class="user_info_r"><a href="<?php echo Yii::app()->createUrl('search/index', array('tab'=>'people', 'filter_age_from'=>(date('Y') - date('Y', strtotime($data->birthday)) - 1), 'filter_age_to'=>(date('Y') - date('Y', strtotime($data->birthday)) + 1)));?>"><?php echo Yii::app()->dateFormatter->formatDateTime($data->birthday, 'long',null); ?></a></td>
						</tr>
					<?php } ?>
					<?php if($data->love_status){ ?>
						<tr>
							<td class="user_info_l">Семейное положение:</td>
							<td class="user_info_r">
								<a href="<?php echo Yii::app()->createUrl('search/index', array('tab'=>'people', 'filter_love_status'=>$data->love_status));?>">
									<?php if($data->sex == 'W'){ ?>
										<?php echo CHtml::encode($data->loveStatus->name_w); ?>
									<?php }else{ ?>
										<?php echo CHtml::encode($data->loveStatus->name_m); ?>
									<?php } ?>
								</a>
							</td>
						</tr>
					<?php } ?>
					<?php if($data->teach){ ?>
						<tr>
							<td class="user_info_l">Место учебы:</td>
							<td class="user_info_r"><a href="<?php echo Yii::app()->createUrl('search/index', array('tab'=>'people', 'filter_teach'=>$data->teach));?>"><?php echo CHtml::encode($data->teach); ?></a></td>
						</tr>
					<?php } ?>
					<?php if($data->work){ ?>
						<tr>
							<td class="user_info_l">Место работы:</td>
							<td class="user_info_r"><a href="<?php echo Yii::app()->createUrl('search/index', array('tab'=>'people', 'filter_work'=>$data->work));?>"><?php echo CHtml::encode($data->work); ?></a></td>
						</tr>
					<?php } ?>
					<?php if($data->about){ ?>
						<tr>
							<td class="user_info_l">О себе:</td>
							<td class="user_info_r">
								<p><?php echo CHtml::encode($data->about); ?></p>
							</td>
						</tr>
					<?php } ?>
					<?php if($data->address){ ?>
						<tr class="hidden">
							<td class="user_info_l">Адресс:</td>
							<td class="user_info_r"><?php echo CHtml::encode($data->address); ?></td>
						</tr>
					<?php } ?>						
					<?php if($data->phone){ ?>
						<tr class="hidden">
							<td class="user_info_l">Телефон:</td>
							<td class="user_info_r"><?php echo CHtml::encode($data->phone); ?></td>
						</tr>
					<?php } ?>		
					<?php if($data->skype){ ?>
						<tr class="hidden">
							<td class="user_info_l">Skype:</td>
							<td class="user_info_r"><?php echo CHtml::encode($data->skype); ?></td>
						</tr>
					<?php } ?>	
					<?php if($data->website){ ?>
						<tr class="hidden">
							<td class="user_info_l">Личный сайт:</td>
							<td class="user_info_r"><a href="<?php echo CHtml::encode($data->website); ?>"><?php echo CHtml::encode($data->website); ?></a></td>
						</tr>
					<?php } ?>	
					<?php if($data->blog){ ?>
						<tr class="hidden">
							<td class="user_info_l">Блог:</td>
							<td class="user_info_r"><a href="<?php echo CHtml::encode($data->blog); ?>"><?php echo CHtml::encode($data->blog); ?></a></td>
						</tr>
					<?php } ?>	
					<?php if($data->youtube){ ?>
						<tr class="hidden">
							<td class="user_info_l">Yоutube канал:</td>
							<td class="user_info_r"><a href="<?php echo CHtml::encode($data->youtube); ?>"><?php echo CHtml::encode($data->youtube); ?></a></td>
						</tr>
					<?php } ?>																						
					<?php if($data->interests){ ?>
						<tr class="hidden">
							<td class="user_info_l">Интересы:</td>
							<td class="user_info_r">
								<p><?php echo CHtml::encode($data->interests); ?></p>
							</td>
						</tr>
					<?php } ?>					
					<?php if($data->favorite_music){ ?>
						<tr class="hidden">
							<td class="user_info_l">Любимая музыка:</td>
							<td class="user_info_r">
								<p><?php echo CHtml::encode($data->favorite_music); ?></p>
							</td>
						</tr>
					<?php } ?>	
					<?php if($data->favorite_film){ ?>
						<tr class="hidden">
							<td class="user_info_l">Любимый фильм:</td>
							<td class="user_info_r">
								<p><?php echo CHtml::encode($data->favorite_film); ?></p>
							</td>
						</tr>
					<?php } ?>
					<?php if($data->favorite_book){ ?>
						<tr class="hidden">
							<td class="user_info_l">Любимые книги:</td>
							<td class="user_info_r">
								<p><?php echo CHtml::encode($data->favorite_book); ?></p>
							</td>
						</tr>
					<?php } ?>	
					<?php if($data->favorite_game){ ?>
						<tr class="hidden">
							<td class="user_info_l">Любимые игры:</td>
							<td class="user_info_r">
								<p><?php echo CHtml::encode($data->favorite_game); ?></p>
							</td>
						</tr>
					<?php } ?>																		
				</table>
				<div class="ovh">
					<div class="c">
						<div class="more_btn cc" id="more_info">Показать больше информации</div>
						<div class="more_btn cc hidden" id="less_info">Показать меньше информации</div>
					</div>
				</div>
			</div>
			
			<?php 
				if($data->id == Yii::app()->user->id || $data->view_music == 1 || ($data->view_music == 2 && isset($data->isFriend) && $data->isFriend->status)){
					$this->renderPartial('_musics',array(
						'countMusics'=>$data->countMusics,
						'musics'	 =>$data->musics
					)); 
				}
			?>	
			
			<?php 
				$this->renderPartial('_comments',array(
					'wall_comments' => $data->wall_comments,
					'isFriend' => (isset($data->isFriend) && $data->isFriend->status) ? true : false,
					'countComments' => $countComments,
					'comments'	=> $comments,
					'parent_id' => 0,
					'offset' => 10,
					'limit' => 10
				)); 
			?>	
		</div>
		<div class="clear"></div>
	<?php else : ?>
		<div class="l">
			<div class="u_block1">
				<div class="u_photo">
					<?php if($data->avatar){ ?>
						<a href="<?php echo Yii::app()->createUrl('albums/photo', array('id'=>$data->avatar));?>" class="photoBg">
							<?php echo $this->material_image(0, $data->avatar_info->name, '200', 'photos/'. $data->id . '/' . 0); ?>
						</a>
					<?php }else{ ?>
						<?php echo $this->material_image(0, 'noimage.gif', '200', ''); ?>
					<?php } ?>					
				</div>
			</div>
		</div>
		<div class="r">
			<div class="user_head">
				<h1><?php echo CHtml::encode($data->full_name); ?></h1>
				<p>
					У Вас нет доступа к даной странице пользователя
				</p>
			</div>
		</div>
		<div class="clear"></div>	
	<?php endif; ?>
</div>
	